class RandomizedSet {
public:
    unordered_map<int,int> hash;
    vector<int> ans;
    /** Initialize your data structure here. */
    RandomizedSet() {
        srand((unsigned)time(NULL));
    }
    
    /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */
    bool insert(int val) {
        if(hash.count(val)){
            return false;
        }
        int index = ans.size();
        hash[val] = index;
        ans.push_back(val);
        return true;
    }
    
    /** Removes a value from the set. Returns true if the set contained the specified element. */
    bool remove(int val) {
        if(!hash.count(val)){
            return false;
        }
        int index = hash[val];
        ans[index] = ans.back();
        hash[ans.back()] = index;
        ans.pop_back();
        hash.erase(val);
        return true;
    }
    
    /** Get a random element from the set. */
    int getRandom() {
        int randNum = rand() % ans.size();
        return ans[randNum];
    }
};
